package cheme.ProcessModel.Interpreter.Parsers;

import java.util.HashMap;
import java.util.Map;

import cheme.ProcessModel.ProcessModelConstants;
import cheme.ProcessModel.Equations.Equation;
import cheme.ProcessModel.ProcessUnits.Streams.Tags.OverallTagComponent;
import cheme.ProcessModel.ProcessUnits.Streams.Tags.Tag;
import cheme.ProcessModel.ProcessUnits.Streams.Tags.TagComponent;

public class ParserFactory
{
	private static Map<Object, IParser> parsers = new HashMap<Object, IParser>();
	
	public static IParser getParser(Object type)
	{
		IParser parser = parsers.get(type);
		
		if(null == parser)
		{
			if(type instanceof Tag)
			{
				parser = new StreamDeclarationParser();
			}
			else if(type instanceof OverallTagComponent)
			{
				parser = new OverallStreamParser();
			}
			else if(type instanceof TagComponent)
			{
				parser = new StreamComponentParser();
			}
			else if(type instanceof Equation)
			{
				parser = new EquationParser();
			}
			else if(type.equals(ProcessModelConstants.VARIABLE_LABEL))
			{
				parser = new IdentifierParser();
			}
			else if(type.equals(ProcessModelConstants.VARIABLE_QUANTITY))
			{
				parser = new QuantityParser();
			}
			else if(type.equals(ProcessModelConstants.VARIABLE_UNITS))
			{
				parser = new UnitParser();
			}
			else if(type.equals(ProcessModelConstants.VARIABLE_MATERIAL))
			{
				/*
				 * Note: no checking on the material. A user should be able to 
				 * write in anything they want in this field.
				 * 
				 * Water and some acid.
				 * H2O.
				 * Mystery Liquid.
				 */
				parser = DummyParser.getInstance();
			}
			else
			{
				parser = DummyParser.getInstance();
			}
			
			parsers.put(type, parser);
		}
		
		return parser;
	}
}
